package com.yunjing.elasticjob.service;


import com.yunjing.elasticjob.entity.JobConfig;
import org.quartz.Job;
import org.quartz.JobBuilder;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author zhiqi.shao
 * @Date 2018/6/14 14:29
 */
@Component
public class JobDetailBuilder  {

    public JobDetail build(JobConfig jobConfig, Class<? extends Job> jobClass) {
        Map jobData = BeanMap.create(jobConfig);
        return JobBuilder.newJob(jobClass).withIdentity(String.valueOf(jobConfig.getId()), jobConfig.getGroupName())
                .usingJobData(new JobDataMap(jobData)).build();
    }
}
